#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2021/3/29 0029 21:36
# @Author : Moyan# @Site : 
# @File : ImageCrawling.py
# @Software: PyCharm
import requests
from lxml import etree

url = "https://www.meishij.net/chufang/diy/guowaicaipu1/japan/"
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"
    }
response = requests.get(url,headers = headers)
# print(response)# 将字符串转化为html代码
root = etree.HTML(response.content)
image_list = root.xpath('//div[@class="listtyle1"]/a')
for image in image_list:
      # . : 表示从当前节点开始获取
    image_alt = image.xpath('./img/@alt')[0]
    image_src = image.xpath('./img/@src')[0]
    image_rq = image.xpath('./div/div/div/span/text()')[0].split(' ')[3]
      # 拼接内容
    print(image_alt+'('+image_rq+'人气'+')',image_src)
